/**
 * Window Adjustment Utility
 * 用于窗口大小调整的工具函数
 */

/**
 * 设置头部显示状态的脚本
 * @param {boolean} showHead - 是否显示头部
 */
const getHeadDisplayScript = (showHead) => {
  return `
    {
      const errorHeadElement = document.querySelector('.login-error-head');
      const applicationHeadElement = document.querySelector('.application-head');
      
      if (errorHeadElement) {
        errorHeadElement.style.display = ${showHead} ? 'block' : 'none';
      }
      if (applicationHeadElement) {
        applicationHeadElement.style.display = ${showHead} ? 'block' : 'none';
      }
    }
  `;
};

/**
 * 获取内容尺寸的脚本
 */
const getContentSizeScript = () => {
  return `
    new Promise(resolve => {
      const getContentSize = () => {
        const errorPage = document.querySelector('.login-error');
        const appPage = document.querySelector('.application');
        const target = errorPage || appPage;
        
        if (!target) return resolve(null);
        
        // 计算包含边框的实际尺寸
        const style = window.getComputedStyle(target);
        const borderWidth = parseFloat(style.borderLeftWidth) + parseFloat(style.borderRightWidth);
        const borderHeight = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
        return {
          winWidth: Math.ceil(target.clientWidth + borderWidth),
          winHeight: Math.ceil(target.clientHeight + borderHeight)
        };
      }
      
      // 等待DOM稳定
      if (document.readyState === 'complete') {
        resolve(getContentSize());
      } else {
        document.addEventListener('DOMContentLoaded', () => resolve(getContentSize()));
      }
    })
  `;
};

module.exports = {
  getHeadDisplayScript,
  getContentSizeScript
};